#Turnbull-Dugarte & López-Ortega (2025)

#---- Replication script #4 ----
#---- REQUIRES COMPLETION OF SCRIPT #1 AND SCRIPT #2 FIRST ----

##NB: Table A5 and Table A6 are not reproduced in this code as these are descriptive tables
##that provide details on the experimental design. 


###TABLE A1 and TABLE A2###
directUK <- directUK |> 
  mutate(gender_bin= case_when(gender==2 ~ NA_real_,
                               TRUE ~ gender),
         gender_bin= case_when(gender_bin== 1~1, gender_bin==0 ~ 2),
         gender_text= case_when(gender== 0 ~ "Man",
                                gender== 1 ~ "Woman",
                                gender== 2 ~ "Non-binary"),
         Education_text= case_when(degree== 1 ~ "Lower than university",
                                   degree== 0 ~ "University degree or more"
         )
  ) |> 
  drop_na(gender_bin, age, Education_text)

directUK <- directUK %>%
  mutate(
    sex_pref = case_when(
      sex_pref == 1 ~ "men only",
      sex_pref == 5 ~ "mainly men",
      sex_pref == 6 ~ "mainly women",
      sex_pref == 7 ~ "women only",
      sex_pref == 3 ~ "both men and women equally"
    ),
    tinder = case_when(
      tinder == 1 ~ "Never used",
      tinder == 2 ~ "A couple days",
      tinder == 3 ~ "1-6 months",
      tinder == 4 ~ "6 months-2 years",
      tinder == 5 ~ "2-5 years",
      tinder == 6 ~ ">5 years"
    )
  ) |> 
  mutate(
    sexual_identity = case_when(
      gender_text == "Man" & sex_pref %in% c("men only") ~ "Gay",
      gender_text == "Woman" & sex_pref %in% c("women only") ~ "Lesbian",
      gender_text == "Woman" & sex_pref %in% c("both men and women equally", "mainly women", "mainly men") ~ "Bi woman",
      gender_text == "Man" & sex_pref %in% c("both men and women equally", "mainly women", "mainly men")  ~ "Bi man",
      gender_text == "Man" & sex_pref %in% c("women only") ~ "Man hetero",
      gender_text == "Woman" & sex_pref %in% c("men only") ~ "Woman hetero",
      TRUE ~ NA_character_  # For other cases or missing values
    )
  )



datasummary(gender_text + Education_text + sexual_identity + partyID_full + tinder + 1 ~ N + Percent(fn = function(x, y) 100 * length(x) / length(y)), 
            data = directUK, output="tables_appendix/TableA1.tex")

datasummary(age + ingroup_affect + outgroup_affect ~
              Mean + SD + Min + Median + Max,
            data = directUK,
            fmt = "%.2f",  
            output = "tables_appendix/TableA2.tex")



###TABLE A3 and TABLE A4###
directES <- directES |> 
  mutate(gender_bin= case_when(gender==2 ~ NA_real_,
                               TRUE ~ gender),
         gender_bin= case_when(gender_bin== 1~1, gender_bin==0 ~ 2),
         gender_text= case_when(gender== 0 ~ "Man",
                                gender== 1 ~ "Woman",
                                gender== 2 ~ "Non-binary"),
         Age= as.numeric(factor(Age)),
         Education= case_when(educ>= 4 ~ 2,
                              TRUE ~ 1),
         Education_text= case_when(Education== 1 ~ "Lower than university",
                                   Education== 2 ~ "University degree or more"
         )
  ) |> 
  drop_na(gender_bin, Age, Education) 

directES <- directES %>%
  mutate(
    sex_pref = case_when(
      sex_pref == 1 ~ "men only",
      sex_pref == 5 ~ "mainly men",
      sex_pref == 6 ~ "mainly women",
      sex_pref == 7 ~ "women only",
      sex_pref == 3 ~ "both men and women equally"
    ),
    tinder = case_when(
      tinder == 1 ~ "Never used",
      tinder == 2 ~ "A couple days",
      tinder == 3 ~ "1-6 months",
      tinder == 4 ~ "6 months-2 years",
      tinder == 5 ~ "2-5 years",
      tinder == 6 ~ ">5 years"
    )
  ) |> 
  mutate(
    sexual_identity = case_when(
      gender_text == "Man" & sex_pref %in% c("men only") ~ "Gay",
      gender_text == "Woman" & sex_pref %in% c("women only") ~ "Lesbian",
      gender_text == "Woman" & sex_pref %in% c("both men and women equally", "mainly women", "mainly men") ~ "Bi woman",
      gender_text == "Man" & sex_pref %in% c("both men and women equally", "mainly women", "mainly men")  ~ "Bi man",
      gender_text == "Man" & sex_pref %in% c("women only") ~ "Man hetero",
      gender_text == "Woman" & sex_pref %in% c("men only") ~ "Woman hetero",
      TRUE ~ NA_character_  # For other cases or missing values
    )
  )

datasummary(gender_text + Education_text + sexual_identity + partyID_full + tinder + 1 ~ N + Percent(fn = function(x, y) 100 * length(x) / length(y)), 
            data = directES, output="tables_appendix/TableA3.tex")
datasummary(age + ingroup_affect + outgroup_affect ~
              Mean + SD + Min + Median + Max,
            data = tinder_conjoint_ES,
            fmt = "%.2f",  
            output="tables_appendix/TableA4.tex")



###FIGURE A1###

directUK_noCONS <- directUK %>%
  filter(!(partyID_full %in% c("Plaid Cymru", "SNP", "Reform UK", "Conservative party")))

modC<- lm(direct_votesCon ~ partyID_full, data=directUK_noCONS)
directUK_noCONS$predicted4<-predict(modC, directUK_noCONS)

mean_votesCon <- aggregate(direct_votesCon ~ partyID_full, data = directUK_noCONS, FUN = mean)
se_votesCon <- aggregate(direct_votesCon ~ partyID_full, data = directUK_noCONS, FUN = function(x) sd(x)/sqrt(length(x)))

directvotesCon <- merge(mean_votesCon, se_votesCon, by = "partyID_full")
colnames(directvotesCon) <- c("partyID_full", "mean_votesCon", "se_votesCon")

directvotesCon$lower90 <- directvotesCon$mean_votesCon - (1.645 * directvotesCon$se_votesCon)
directvotesCon$higher90 <- directvotesCon$mean_votesCon + (1.645 * directvotesCon$se_votesCon)
directvotesCon$lower95 <- directvotesCon$mean_votesCon - (1.96 * directvotesCon$se_votesCon)
directvotesCon$higher95 <- directvotesCon$mean_votesCon + (1.96 * directvotesCon$se_votesCon)
directvotesCon$lower99 <- directvotesCon$mean_votesCon - (2.58 * directvotesCon$se_votesCon)
directvotesCon$higher99 <- directvotesCon$mean_votesCon + (2.58 * directvotesCon$se_votesCon)
directvotesCon$lower999 <- directvotesCon$mean_votesCon - (3.29 * directvotesCon$se_votesCon)
directvotesCon$higher999 <- directvotesCon$mean_votesCon + (3.29 * directvotesCon$se_votesCon)

col3 <- c("red2","orange1","green4")
votesConplot<- directvotesCon %>% 
  ggplot(aes(partyID_full, color=partyID_full)) +
  scale_fill_manual(values = col3) +
  scale_color_manual(values = col3)+
  geom_vline(xintercept = 0.5, colour="gray", linetype="dashed")+ ##.46 median acceptance
  geom_segment(aes(x=lower90, xend=higher90, y=partyID_full, yend=partyID_full), size=4, alpha=1, position = position_nudge(y = .4))+ 
  geom_segment(aes(x=lower95, xend=higher95, y=partyID_full, yend=partyID_full), size=3, alpha=.8, position = position_nudge(y = .4))+ 
  geom_segment(aes(x=lower99, xend=higher99, y=partyID_full, yend=partyID_full), size=2, alpha=.6, position = position_nudge(y = .4))+
  geom_point(aes(x=mean_votesCon, y=partyID_full), fill="white", color="grey67", size=2.5,  pch=21, position = position_nudge(y = .4))+
  labs(y=NULL, subtitle='Is voting for the Conservatives a red flag in a partner?', x="")+
  theme_ggdist()+
  xlim(0,1)+
  theme(legend.position = "none") +
  geom_jitter(data=directUK_noCONS, aes(y=partyID_full, x=predicted4, fill=partyID_full),
              height=.3, width=.2,size=3, alpha=.2,
              pch=21, color="grey57")+  
  geom_label(
    aes(label = sprintf("%0.2f", round(mean_votesCon, digits = 2)), y = partyID_full, x = mean_votesCon),
    size=3, fontface = "bold")+
  geom_label(
    aes(label = partyID_full, x = mean_votesCon, y = partyID_full),
    nudge_x = .15, size=3, fontface = "bold")+
  theme(strip.background = element_blank(),
        strip.text = element_blank(),
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank(),
        plot.subtitle = element_text(face="bold", hjust=0))+
  coord_flip()
ggsave("figures_appendix/FigureA1.png")


###FIGURE A2###


directES_noPP <- directES %>%
  filter(!(partyID_full %in% c("Other", "VOX", "PP")))
modP<- lm(direct_votesPP ~ partyID_full, data=directES_noPP)
directES_noPP$predicted4<-predict(modP, directES_noPP)

mean_votesPP <- aggregate(direct_votesPP ~ partyID_full, data = directES_noPP, FUN = mean)
se_votesPP <- aggregate(direct_votesPP ~ partyID_full, data = directES_noPP, FUN = function(x) sd(x)/sqrt(length(x)))

directvotesPP <- merge(mean_votesPP, se_votesPP, by = "partyID_full")
colnames(directvotesPP) <- c("partyID_full", "mean_votesPP", "se_votesPP")


directvotesPP$lower90 <- directvotesPP$mean_votesPP - (1.645 * directvotesPP$se_votesPP)
directvotesPP$higher90 <- directvotesPP$mean_votesPP + (1.645 * directvotesPP$se_votesPP)
directvotesPP$lower95 <- directvotesPP$mean_votesPP - (1.96 * directvotesPP$se_votesPP)
directvotesPP$higher95 <- directvotesPP$mean_votesPP + (1.96 * directvotesPP$se_votesPP)
directvotesPP$lower99 <- directvotesPP$mean_votesPP - (2.58 * directvotesPP$se_votesPP)
directvotesPP$higher99 <- directvotesPP$mean_votesPP + (2.58 * directvotesPP$se_votesPP)
directvotesPP$lower999 <- directvotesPP$mean_votesPP - (3.29 * directvotesPP$se_votesPP)
directvotesPP$higher999 <- directvotesPP$mean_votesPP + (3.29 * directvotesPP$se_votesPP)

col4 <- c("purple","red2","deeppink")
votesPPplot<- directvotesPP %>% 
  ggplot(aes(partyID_full, color=partyID_full)) +
  scale_fill_manual(values = col4) +
  scale_color_manual(values = col4)+
  geom_vline(xintercept = 0.5, colour="gray", linetype="dashed")+ ##.46 median acceptance
  geom_segment(aes(x=lower90, xend=higher90, y=partyID_full, yend=partyID_full), size=4, alpha=1, position = position_nudge(y = .4))+ 
  geom_segment(aes(x=lower95, xend=higher95, y=partyID_full, yend=partyID_full), size=3, alpha=.8, position = position_nudge(y = .4))+ 
  geom_segment(aes(x=lower99, xend=higher99, y=partyID_full, yend=partyID_full), size=2, alpha=.6, position = position_nudge(y = .4))+
  geom_point(aes(x=mean_votesPP, y=partyID_full), fill="white", color="grey67", size=2.5,  pch=21, position = position_nudge(y = .4))+
  labs(y=NULL, subtitle='Is voting for the PP a red flag in a partner?', x="")+
  theme_ggdist()+
  xlim(0,1)+
  theme(legend.position = "none") +
  geom_jitter(data=directES_noPP, aes(y=partyID_full, x=predicted4, fill=partyID_full),
              height=.3, width=.2,size=3, alpha=.2,
              pch=21, color="grey57")+  
  geom_label(
    aes(label = sprintf("%0.2f", round(mean_votesPP, digits = 2)), y = partyID_full, x = mean_votesPP),
    size=3, fontface = "bold")+
  geom_label(
    aes(label = partyID_full, x = mean_votesPP, y = partyID_full),
    nudge_x = .15, size=3, fontface = "bold")+
  theme(strip.background = element_blank(),
        strip.text = element_blank(),
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank(),
        plot.subtitle = element_text(face="bold", hjust=0))+
  coord_flip()
ggsave("figures_appendix/FigureA2.png")


###FIGURE A3###
mm.1 <- mm(tinder_conjoint_UK, selected ~ FLAG + BI + TRANS + PROS + CONGRUENCE + ETHNICITY + EMOTION + RELATIONSHIP + DISTANCE + EDUCATION_SLIM + JOB_SLIM + PARTY,
           id = ~ ResponseId, h0 = 0.5)

plot(mm.1, feature_headers = FALSE) +
  ggplot2::facet_wrap(~feature, ncol = 1L,
                      scales = "free_y", strip.position = "right") + 
  geom_point(size=1.5)+ 
  geom_vline(xintercept = 0.46, colour="gray33")+
  theme(legend.position = "none",
        strip.text = element_blank())+
  geom_text(
    aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = .22),
    size=3, fontface = "bold")
ggsave("figures_appendix/FigureA3.png")

###FIGURE A4###

mmES.1 <- mm(tinder_conjoint_ES, selected ~ FLAG + BI + TRANS + VEG + 
               CONGRUENCE + RELATIONSHIP + DISTANCE + EDUCATION_SLIM + 
               JOB_SLIM + PARTY, id = ~ ResponseId, h0 = 0.5)
plot(mmES.1, feature_headers = FALSE) +
  ggplot2::facet_wrap(~feature, ncol = 1L,
                      scales = "free_y", strip.position = "right") + 
  geom_point(size=1.5)+ 
  geom_vline(xintercept = 0.46, colour="gray33")+
  theme(legend.position = "none",
        strip.text = element_blank())+
  geom_text(
    aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = .29),
    size=3, fontface = "bold")
ggsave("figures_appendix/FigureA4.png")


###FIGURE A5###
mm.1 <- mm(tinder_conjoint_UK_noReform, selected ~ FLAG + BI + TRANS + PROS + CONGRUENCE + ETHNICITY + EMOTION + RELATIONSHIP + DISTANCE + EDUCATION_SLIM + JOB_SLIM + PARTY,
           id = ~ ResponseId, h0 = 0.5)

mm.1$lower90 <- mm.1$estimate - (1.645 * mm.1$std.error)
mm.1$higher90 <- mm.1$estimate + (1.645 * mm.1$std.error)
mm.1$lower95 <- mm.1$estimate - (1.96 * mm.1$std.error)
mm.1$higher95 <- mm.1$estimate + (1.96 * mm.1$std.error)
mm.1$lower99 <- mm.1$estimate - (2.58 * mm.1$std.error)
mm.1$higher99 <- mm.1$estimate + (2.58 * mm.1$std.error)
mm.1$lower999 <- mm.1$estimate - (3.29 * mm.1$std.error)
mm.1$higher999 <- mm.1$estimate + (3.29 * mm.1$std.error)
mm.1<-subset(mm.1, feature %in% c("PARTY")) 

mmplot1<- mm.1 %>% 
  ggplot(aes(level)) +
  geom_vline(xintercept = .46, colour="gray", linetype="dashed")+ ##.46 median acceptance
  geom_segment(aes(x=lower90, xend=higher90, y=level, yend=level), size=4, alpha=1)+ 
  geom_segment(aes(x=lower95, xend=higher95, y=level, yend=level), size=3, alpha=.8)+ 
  geom_segment(aes(x=lower99, xend=higher99, y=level, yend=level), size=2, alpha=.6)+
  facet_grid(feature~., scales='free', space='free') +  
  geom_point(aes(x=estimate, y=level), fill="white", color="grey67", size=2.5,  pch=21)+
  labs(y=NULL, subtitle='Marginal means (MM)', x="")+
  theme_ggdist()+
  theme(legend.position = "none") +
  xlim(.3,.6)+
  geom_label(
    aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
    nudge_y = .3, size=2.5, fontface = "bold")+
  geom_label(
    aes(label = level, y = level, x = estimate),
    nudge_y = -.3, size=2.5, fontface = "bold")+
  theme(strip.background = element_blank(),
        strip.text = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        plot.subtitle = element_text(face="bold", hjust=.5))

amce.1 <- amce(tinder_conjoint_UK_noReform, selected ~ FLAG + BI + TRANS + PROS + CONGRUENCE + ETHNICITY + EMOTION + RELATIONSHIP + DISTANCE + EDUCATION_SLIM + JOB_SLIM + PARTY,
               id = ~ ResponseId)

amce.1$lower90 <- amce.1$estimate - (1.645 * amce.1$std.error)
amce.1$higher90 <- amce.1$estimate + (1.645 * amce.1$std.error)
amce.1$lower95 <- amce.1$estimate - (1.96 * amce.1$std.error)
amce.1$higher95 <- amce.1$estimate + (1.96 * amce.1$std.error)
amce.1$lower99 <- amce.1$estimate - (2.58 * amce.1$std.error)
amce.1$higher99 <- amce.1$estimate + (2.58 * amce.1$std.error)
amce.1$lower999 <- amce.1$estimate - (3.29 * amce.1$std.error)
amce.1$higher999 <- amce.1$estimate + (3.29 * amce.1$std.error)

amce.1<-subset(amce.1, feature %in% c("PARTY")) 
amce.1<-subset(amce.1, level %in% c("Reform UK", "Lib Dem", "Labour", "Greens")) 

amceplot1<- amce.1 %>% 
  ggplot(aes(level)) +
  geom_segment(aes(x=lower90, xend=higher90, y=level, yend=level), size=4, alpha=1)+ 
  geom_segment(aes(x=lower95, xend=higher95, y=level, yend=level), size=3, alpha=.8)+ 
  geom_segment(aes(x=lower99, xend=higher99, y=level, yend=level), size=2, alpha=.6)+
  facet_grid(feature~., scales='free', space='free') +  
  geom_point(aes(x=estimate, y=level), fill="white", color="grey67", size=2.5,  pch=21)+
  labs(y=NULL, subtitle='Average marginal component effect (AMCE)', x="")+
  theme_ggdist()+
  theme(legend.position = "none") +
  xlim(-.2,.22)+
  geom_label(
    aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
    nudge_y = .25, size=2.5, fontface = "bold")+
  geom_label(
    aes(label = level, y = level, x = estimate),
    nudge_y = -.25, size=2.5, fontface = "bold")+
  theme(strip.background = element_blank(),
        strip.text = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        plot.subtitle = element_text(face="bold", hjust=.5)) + 
  geom_vline(xintercept = 0, colour="gray", linetype="dashed") ##.46 median acceptance

mmplot1+amceplot1+
  plot_annotation(caption = 'Confidence intervals at 99%, 95% & 90%')
ggsave("figures_appendix/FigureA5.png", height=9, units="cm", dpi = 900)



###FIGURE A6###

mmES.1 <- mm(tinder_conjoint_ES_noVOX, selected ~ FLAG + BI + TRANS + VEG + 
               CONGRUENCE + RELATIONSHIP + DISTANCE + EDUCATION_SLIM + 
               JOB_SLIM + PARTY, id = ~ ResponseId, h0 = 0.5)

mmES.1$lower90 <- mmES.1$estimate - (1.645 * mmES.1$std.error)
mmES.1$higher90 <- mmES.1$estimate + (1.645 * mmES.1$std.error)
mmES.1$lower95 <- mmES.1$estimate - (1.96 * mmES.1$std.error)
mmES.1$higher95 <- mmES.1$estimate + (1.96 * mmES.1$std.error)
mmES.1$lower99 <- mmES.1$estimate - (2.58 * mmES.1$std.error)
mmES.1$higher99 <- mmES.1$estimate + (2.58 * mmES.1$std.error)
mmES.1$lower999 <- mmES.1$estimate - (3.29 * mmES.1$std.error)
mmES.1$higher999 <- mmES.1$estimate + (3.29 * mmES.1$std.error)

mmES.1<-subset(mmES.1, feature %in% c("PARTY")) 

ESmmplot1<- mmES.1 %>% 
  ggplot(aes(level)) +
  geom_vline(xintercept = .44, colour="gray", linetype="dashed")+ ##.46 median acceptance
  geom_segment(aes(x=lower90, xend=higher90, y=level, yend=level), size=4, alpha=1)+ 
  geom_segment(aes(x=lower95, xend=higher95, y=level, yend=level), size=3, alpha=.8)+ 
  geom_segment(aes(x=lower99, xend=higher99, y=level, yend=level), size=2, alpha=.6)+
  facet_grid(feature~., scales='free', space='free') +  
  geom_point(aes(x=estimate, y=level), fill="white", color="grey67", size=2.5,  pch=21)+
  labs(y=NULL, subtitle='Marginal means (MM)', x="")+
  theme_ggdist()+
  theme(legend.position = "none") +
  xlim(.3,.6)+
  geom_label(
    aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
    nudge_y = .25, size=2.5, fontface = "bold")+
  geom_label(
    aes(label = level, y = level, x = estimate),
    nudge_y = -.25, size=2.5, fontface = "bold")+
  theme(strip.background = element_blank(),
        strip.text = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        plot.subtitle = element_text(face="bold", hjust=.5))

amceES.1 <- amce(tinder_conjoint_ES_noVOX, selected ~ FLAG + BI + TRANS + VEG +
                   CONGRUENCE + RELATIONSHIP + DISTANCE + EDUCATION_SLIM +
                   JOB_SLIM + PARTY, id = ~ ResponseId)

amceES.1$lower90 <- amceES.1$estimate - (1.645 * amceES.1$std.error)
amceES.1$higher90 <- amceES.1$estimate + (1.645 * amceES.1$std.error)
amceES.1$lower95 <- amceES.1$estimate - (1.96 * amceES.1$std.error)
amceES.1$higher95 <- amceES.1$estimate + (1.96 * amceES.1$std.error)
amceES.1$lower99 <- amceES.1$estimate - (2.58 * amceES.1$std.error)
amceES.1$higher99 <- amceES.1$estimate + (2.58 * amceES.1$std.error)
amceES.1$lower999 <- amceES.1$estimate - (3.29 * amceES.1$std.error)
amceES.1$higher999 <- amceES.1$estimate + (3.29 * amceES.1$std.error)

amceES.1<-subset(amceES.1, feature %in% c("PARTY")) 
amceES.1<-subset(amceES.1, level %in% c("PSOE", "Sumar", "VOX")) 

ESamceplot1<- amceES.1 %>% 
  ggplot(aes(level)) +
  geom_vline(xintercept = 0, colour="gray", linetype="dashed")+ ##.46 median acceptance
  geom_segment(aes(x=lower90, xend=higher90, y=level, yend=level), size=4, alpha=1)+ 
  geom_segment(aes(x=lower95, xend=higher95, y=level, yend=level), size=3, alpha=.8)+ 
  geom_segment(aes(x=lower99, xend=higher99, y=level, yend=level), size=2, alpha=.6)+
  facet_grid(feature~., scales='free', space='free') +  
  geom_point(aes(x=estimate, y=level), fill="white", color="grey67", size=2.5,  pch=21)+
  labs(y=NULL, subtitle='Average marginal component effect (AMCE)', x="")+
  theme_ggdist()+
  theme(legend.position = "none") +
  xlim(-.2,.2)+
  geom_label(
    aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
    nudge_y = .2, size=2.5, fontface = "bold")+
  geom_label(
    aes(label = level, y = level, x = estimate),
    nudge_y = -.2, size=2.5, fontface = "bold")+
  theme(strip.background = element_blank(),
        strip.text = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        plot.subtitle = element_text(face="bold", hjust=.5))

ESmmplot1+ESamceplot1+
  plot_annotation(caption = 'Confidence intervals at 99%, 95% & 90%')
ggsave("figures_appendix/FigureA6.png", height=9, units="cm", dpi = 900)



###FIGURE A7###

gender_UK <- cj(tinder_conjoint_UK, selected ~ FLAG + BI + PROS + TRANS + CONGRUENCE + ETHNICITY + EMOTION + RELATIONSHIP + DISTANCE + EDUCATION_SLIM + JOB_SLIM + PARTY,
                id = ~ ResponseId, estimate="amce",by = ~ resp_gender)


gender_UK$lower90 <- gender_UK$estimate - (1.645 * gender_UK$std.error)
gender_UK$higher90 <- gender_UK$estimate + (1.645 * gender_UK$std.error)
gender_UK$lower95 <- gender_UK$estimate - (1.96 * gender_UK$std.error)
gender_UK$higher95 <- gender_UK$estimate + (1.96 * gender_UK$std.error)
gender_UK$lower99 <- gender_UK$estimate - (2.58 * gender_UK$std.error)
gender_UK$higher99 <- gender_UK$estimate + (2.58 * gender_UK$std.error)
gender_UK$lower999 <- gender_UK$estimate - (3.29 * gender_UK$std.error)
gender_UK$higher999 <- gender_UK$estimate + (3.29 * gender_UK$std.error)
gender_UK<-subset(gender_UK, feature %in% c("PARTY")) 

gen1<- ggplot(gender_UK, aes(y = level, x = estimate, color = BY)) +
  scale_shape_manual(values = c(10, 18)) +
  scale_fill_manual(values = col2) +
  scale_color_manual(values = col2) +
  facet_grid(feature~., scales='free', space='free') +  
  geom_vline(xintercept = 0, colour="grey", linetype="dashed")+
  geom_segment(data = subset(gender_UK, BY == "a woman"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(gender_UK, BY == "a woman"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(gender_UK, BY == "a woman"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6, position = position_nudge(y = .2)) + 
  geom_point(data = subset(gender_UK, BY == "a woman"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21,  
             position = position_nudge(y = .2))+
  geom_segment(data = subset(gender_UK, BY == "a man"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1) + 
  geom_segment(data = subset(gender_UK, BY == "a man"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8) + 
  geom_segment(data = subset(gender_UK, BY == "a man"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6) + 
  geom_point(data = subset(gender_UK, BY == "a man"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21) +
  geom_label(data = subset(gender_UK, BY == "a woman"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = .4), size = 3, fontface = "bold"
  ) +
  geom_label(data = subset(gender_UK, BY == "a man"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = -.2), size = 3, fontface = "bold"
  ) +
  annotate("label", x = -.15, y = 1.2, label = "Men",
           color="black", size=3, fontface="bold", hjust=.5)+
  annotate("label", x = -.15, y = 1, label = "Women",
           color="grey50", size=3, fontface="bold", hjust=.5)+
  labs(y = NULL, subtitle = 'Conditional AMCE', x="")+
  theme_ggdist() +
  xlim(-.2,.3)+
  theme(legend.position = "none",
        strip.background = element_blank(),
        strip.text = element_blank(),
        plot.subtitle = element_text(face="bold", hjust=.5)) 


genderMM_UK <- cj(tinder_conjoint_UK, selected ~ FLAG + BI + PROS + TRANS + CONGRUENCE + ETHNICITY + EMOTION + RELATIONSHIP + DISTANCE + EDUCATION_SLIM + JOB_SLIM + PARTY,
                  id = ~ ResponseId, estimate="mm",by = ~ resp_gender)


genderMM_UK$lower90 <- genderMM_UK$estimate - (1.645 * genderMM_UK$std.error)
genderMM_UK$higher90 <- genderMM_UK$estimate + (1.645 * genderMM_UK$std.error)
genderMM_UK$lower95 <- genderMM_UK$estimate - (1.96 * genderMM_UK$std.error)
genderMM_UK$higher95 <- genderMM_UK$estimate + (1.96 * genderMM_UK$std.error)
genderMM_UK$lower99 <- genderMM_UK$estimate - (2.58 * genderMM_UK$std.error)
genderMM_UK$higher99 <- genderMM_UK$estimate + (2.58 * genderMM_UK$std.error)
genderMM_UK$lower999 <- genderMM_UK$estimate - (3.29 * genderMM_UK$std.error)
genderMM_UK$higher999 <- genderMM_UK$estimate + (3.29 * genderMM_UK$std.error)
genderMM_UK<-subset(genderMM_UK, feature %in% c("PARTY")) 

gen2<- ggplot(genderMM_UK, aes(y = level, x = estimate, color = BY)) +
  scale_shape_manual(values = c(10, 18)) +
  scale_fill_manual(values = col2) +
  scale_color_manual(values = col2) +
  facet_grid(feature~., scales='free', space='free') +  
  geom_segment(data = subset(genderMM_UK, BY == "a woman"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(genderMM_UK, BY == "a woman"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(genderMM_UK, BY == "a woman"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6, position = position_nudge(y = .2)) + 
  geom_point(data = subset(genderMM_UK, BY == "a woman"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21,  
             position = position_nudge(y = .2))+
  geom_segment(data = subset(genderMM_UK, BY == "a man"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1) + 
  geom_segment(data = subset(genderMM_UK, BY == "a man"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8) + 
  geom_segment(data = subset(genderMM_UK, BY == "a man"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6) + 
  geom_point(data = subset(genderMM_UK, BY == "a man"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21) +
  geom_label(data = subset(genderMM_UK, BY == "a woman"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = .4), size = 3, fontface = "bold"
  ) +
  geom_label(data = subset(genderMM_UK, BY == "a man"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = -.2), size = 3, fontface = "bold"
  )+
  labs(y = NULL, subtitle = 'Conditional MM', x="")+
  theme_ggdist() +
  xlim(.1, .7)+
  theme(legend.position = "none",
        strip.background = element_blank(),
        strip.text = element_blank(),
        axis.ticks.y = element_blank(),
        axis.text.y = element_blank(),
        plot.subtitle = element_text(face="bold", hjust=.5))


gen1+gen2
ggsave("figures_appendix/FigureA7.png", height=9, units="cm", dpi = 900)

###FIGURE A8###

gender_spain <- cj(tinder_conjoint_ES, selected ~ FLAG + BI + VEG + TRANS + CONGRUENCE + ETHNICITY + EMOTION + RELATIONSHIP + DISTANCE + EDUCATION_SLIM + JOB_SLIM + PARTY,
                   id = ~ ResponseId, estimate="amce",by = ~ resp_gender)


gender_spain$lower90 <- gender_spain$estimate - (1.645 * gender_spain$std.error)
gender_spain$higher90 <- gender_spain$estimate + (1.645 * gender_spain$std.error)
gender_spain$lower95 <- gender_spain$estimate - (1.96 * gender_spain$std.error)
gender_spain$higher95 <- gender_spain$estimate + (1.96 * gender_spain$std.error)
gender_spain$lower99 <- gender_spain$estimate - (2.58 * gender_spain$std.error)
gender_spain$higher99 <- gender_spain$estimate + (2.58 * gender_spain$std.error)
gender_spain$lower999 <- gender_spain$estimate - (3.29 * gender_spain$std.error)
gender_spain$higher999 <- gender_spain$estimate + (3.29 * gender_spain$std.error)
gender_spain<-subset(gender_spain, feature %in% c("PARTY")) 

gen1<- ggplot(gender_spain, aes(y = level, x = estimate, color = BY)) +
  scale_shape_manual(values = c(10, 18)) +
  scale_fill_manual(values = col2) +
  scale_color_manual(values = col2) +
  facet_grid(feature~., scales='free', space='free') +  
  geom_vline(xintercept = 0, colour="grey", linetype="dashed")+
  geom_segment(data = subset(gender_spain, BY == "a woman"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(gender_spain, BY == "a woman"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(gender_spain, BY == "a woman"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6, position = position_nudge(y = .2)) + 
  geom_point(data = subset(gender_spain, BY == "a woman"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21,  
             position = position_nudge(y = .2))+
  geom_segment(data = subset(gender_spain, BY == "a man"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1) + 
  geom_segment(data = subset(gender_spain, BY == "a man"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8) + 
  geom_segment(data = subset(gender_spain, BY == "a man"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6) + 
  geom_point(data = subset(gender_spain, BY == "a man"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21) +
  geom_label(data = subset(gender_spain, BY == "a woman"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = .4), size = 3, fontface = "bold"
  ) +
  geom_label(data = subset(gender_spain, BY == "a man"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = -.2), size = 3, fontface = "bold"
  ) +
  annotate("label", x = -.15, y = 1.2, label = "Men",
           color="black", size=3, fontface="bold", hjust=.5)+
  annotate("label", x = -.15, y = 1, label = "Women",
           color="grey50", size=3, fontface="bold", hjust=.5)+
  labs(y = NULL, subtitle = 'Conditional AMCE', x="")+
  theme_ggdist() +
  xlim(-.2,.3)+
  theme(legend.position = "none",
        strip.background = element_blank(),
        strip.text = element_blank(),
        plot.subtitle = element_text(face="bold", hjust=.5)) 


genderMM_ES <- cj(tinder_conjoint_ES, selected ~ FLAG + BI + VEG + TRANS + CONGRUENCE + ETHNICITY + EMOTION + RELATIONSHIP + DISTANCE + EDUCATION_SLIM + JOB_SLIM + PARTY,
                  id = ~ ResponseId, estimate="mm",by = ~ resp_gender)


genderMM_ES$lower90 <- genderMM_ES$estimate - (1.645 * genderMM_ES$std.error)
genderMM_ES$higher90 <- genderMM_ES$estimate + (1.645 * genderMM_ES$std.error)
genderMM_ES$lower95 <- genderMM_ES$estimate - (1.96 * genderMM_ES$std.error)
genderMM_ES$higher95 <- genderMM_ES$estimate + (1.96 * genderMM_ES$std.error)
genderMM_ES$lower99 <- genderMM_ES$estimate - (2.58 * genderMM_ES$std.error)
genderMM_ES$higher99 <- genderMM_ES$estimate + (2.58 * genderMM_ES$std.error)
genderMM_ES$lower999 <- genderMM_ES$estimate - (3.29 * genderMM_ES$std.error)
genderMM_ES$higher999 <- genderMM_ES$estimate + (3.29 * genderMM_ES$std.error)
genderMM_ES<-subset(genderMM_ES, feature %in% c("PARTY")) 

gen2<- ggplot(genderMM_ES, aes(y = level, x = estimate, color = BY)) +
  scale_shape_manual(values = c(10, 18)) +
  scale_fill_manual(values = col2) +
  scale_color_manual(values = col2) +
  facet_grid(feature~., scales='free', space='free') +  
  geom_segment(data = subset(genderMM_ES, BY == "a woman"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(genderMM_ES, BY == "a woman"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(genderMM_ES, BY == "a woman"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6, position = position_nudge(y = .2)) + 
  geom_point(data = subset(genderMM_ES, BY == "a woman"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21,  
             position = position_nudge(y = .2))+
  geom_segment(data = subset(genderMM_ES, BY == "a man"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1) + 
  geom_segment(data = subset(genderMM_ES, BY == "a man"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8) + 
  geom_segment(data = subset(genderMM_ES, BY == "a man"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6) + 
  geom_point(data = subset(genderMM_ES, BY == "a man"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21) +
  geom_label(data = subset(genderMM_ES, BY == "a woman"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = .4), size = 3, fontface = "bold"
  ) +
  geom_label(data = subset(genderMM_ES, BY == "a man"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = -.2), size = 3, fontface = "bold"
  )+
  labs(y = NULL, subtitle = 'Conditional MM', x="")+
  theme_ggdist() +
  xlim(.1, .7)+
  theme(legend.position = "none",
        strip.background = element_blank(),
        strip.text = element_blank(),
        axis.ticks.y = element_blank(),
        axis.text.y = element_blank(),
        plot.subtitle = element_text(face="bold", hjust=.5))

gen1+gen2
ggsave("figures_appendix/FigureA8.png", height=9, units="cm", dpi = 900)

###FIGURE A9###

lgbt_uk <- cj(tinder_conjoint_UK, selected ~ FLAG + BI + PROS + TRANS + CONGRUENCE + ETHNICITY + EMOTION + RELATIONSHIP + DISTANCE + EDUCATION_SLIM + JOB_SLIM + PARTY,
              id = ~ ResponseId, estimate="amce", by = ~ queer)


lgbt_uk$lower90 <- lgbt_uk$estimate - (1.645 * lgbt_uk$std.error)
lgbt_uk$higher90 <- lgbt_uk$estimate + (1.645 * lgbt_uk$std.error)
lgbt_uk$lower95 <- lgbt_uk$estimate - (1.96 * lgbt_uk$std.error)
lgbt_uk$higher95 <- lgbt_uk$estimate + (1.96 * lgbt_uk$std.error)
lgbt_uk$lower99 <- lgbt_uk$estimate - (2.58 * lgbt_uk$std.error)
lgbt_uk$higher99 <- lgbt_uk$estimate + (2.58 * lgbt_uk$std.error)
lgbt_uk$lower999 <- lgbt_uk$estimate - (3.29 * lgbt_uk$std.error)
lgbt_uk$higher999 <- lgbt_uk$estimate + (3.29 * lgbt_uk$std.error)
lgbt_uk<-subset(lgbt_uk, feature %in% c("PARTY")) 

gen1<- ggplot(lgbt_uk, aes(y = level, x = estimate, color = BY)) +
  scale_shape_manual(values = c(10, 18)) +
  scale_fill_manual(values = col2) +
  scale_color_manual(values = col2) +
  facet_grid(feature~., scales='free', space='free') +  
  geom_vline(xintercept = 0, colour="grey", linetype="dashed")+
  geom_segment(data = subset(lgbt_uk, BY == "LGBTQ+"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(lgbt_uk, BY == "LGBTQ+"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(lgbt_uk, BY == "LGBTQ+"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6, position = position_nudge(y = .2)) + 
  geom_point(data = subset(lgbt_uk, BY == "LGBTQ+"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21,  
             position = position_nudge(y = .2))+
  geom_segment(data = subset(lgbt_uk, BY == "Heterosexual"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1) + 
  geom_segment(data = subset(lgbt_uk, BY == "Heterosexual"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8) + 
  geom_segment(data = subset(lgbt_uk, BY == "Heterosexual"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6) + 
  geom_point(data = subset(lgbt_uk, BY == "Heterosexual"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21) +
  geom_label(data = subset(lgbt_uk, BY == "LGBTQ+"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = .4), size = 3, fontface = "bold"
  ) +
  geom_label(data = subset(lgbt_uk, BY == "Heterosexual"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = -.2), size = 3, fontface = "bold"
  ) +
  annotate("label", x = -.15, y = 1.2, label = "Heterosexual",
           color="black", size=3, fontface="bold", hjust=.5)+
  annotate("label", x = -.15, y = 1, label = "LGBTQ+",
           color="grey50", size=3, fontface="bold", hjust=.5)+
  labs(y = NULL, subtitle = 'Conditional AMCE', x="")+
  theme_ggdist() +
  xlim(-.2,.5)+
  theme(legend.position = "none",
        strip.background = element_blank(),
        strip.text = element_blank(),
        plot.subtitle = element_text(face="bold", hjust=.5)) 


lgbtMM_UK <- cj(tinder_conjoint_UK, selected ~ FLAG + BI + PROS + TRANS + CONGRUENCE + ETHNICITY + EMOTION + RELATIONSHIP + DISTANCE + EDUCATION_SLIM + JOB_SLIM + PARTY,
                id = ~ ResponseId, estimate="mm",by = ~ queer)


lgbtMM_UK$lower90 <- lgbtMM_UK$estimate - (1.645 * lgbtMM_UK$std.error)
lgbtMM_UK$higher90 <- lgbtMM_UK$estimate + (1.645 * lgbtMM_UK$std.error)
lgbtMM_UK$lower95 <- lgbtMM_UK$estimate - (1.96 * lgbtMM_UK$std.error)
lgbtMM_UK$higher95 <- lgbtMM_UK$estimate + (1.96 * lgbtMM_UK$std.error)
lgbtMM_UK$lower99 <- lgbtMM_UK$estimate - (2.58 * lgbtMM_UK$std.error)
lgbtMM_UK$higher99 <- lgbtMM_UK$estimate + (2.58 * lgbtMM_UK$std.error)
lgbtMM_UK$lower999 <- lgbtMM_UK$estimate - (3.29 * lgbtMM_UK$std.error)
lgbtMM_UK$higher999 <- lgbtMM_UK$estimate + (3.29 * lgbtMM_UK$std.error)
lgbtMM_UK<-subset(lgbtMM_UK, feature %in% c("PARTY")) 

gen2<- ggplot(lgbtMM_UK, aes(y = level, x = estimate, color = BY)) +
  scale_shape_manual(values = c(10, 18)) +
  scale_fill_manual(values = col2) +
  scale_color_manual(values = col2) +
  facet_grid(feature~., scales='free', space='free') +  
  geom_segment(data = subset(lgbtMM_UK, BY == "LGBTQ+"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(lgbtMM_UK, BY == "LGBTQ+"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(lgbtMM_UK, BY == "LGBTQ+"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6, position = position_nudge(y = .2)) + 
  geom_point(data = subset(lgbtMM_UK, BY == "LGBTQ+"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21,  
             position = position_nudge(y = .2))+
  geom_segment(data = subset(lgbtMM_UK, BY == "Heterosexual"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1) + 
  geom_segment(data = subset(lgbtMM_UK, BY == "Heterosexual"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8) + 
  geom_segment(data = subset(lgbtMM_UK, BY == "Heterosexual"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6) + 
  geom_point(data = subset(lgbtMM_UK, BY == "Heterosexual"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21) +
  geom_label(data = subset(lgbtMM_UK, BY == "LGBTQ+"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = .4), size = 3, fontface = "bold"
  ) +
  geom_label(data = subset(lgbtMM_UK, BY == "Heterosexual"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = -.2), size = 3, fontface = "bold"
  )+
  labs(y = NULL, subtitle = 'Conditional MM', x="")+
  theme_ggdist() +
  xlim(.1, .7)+
  theme(legend.position = "none",
        strip.background = element_blank(),
        strip.text = element_blank(),
        axis.ticks.y = element_blank(),
        axis.text.y = element_blank(),
        plot.subtitle = element_text(face="bold", hjust=.5))

gen1+gen2
ggsave("figures_appendix/FigureA9.png", height=9, units="cm", dpi = 900)


###FIGURE A10###
lgbt_spain <- cj(tinder_conjoint_ES, selected ~ FLAG + BI + VEG + TRANS + CONGRUENCE + ETHNICITY + EMOTION + RELATIONSHIP + DISTANCE + EDUCATION_SLIM + JOB_SLIM + PARTY,
                 id = ~ ResponseId, estimate="amce",by = ~ queer)


lgbt_spain$lower90 <- lgbt_spain$estimate - (1.645 * lgbt_spain$std.error)
lgbt_spain$higher90 <- lgbt_spain$estimate + (1.645 * lgbt_spain$std.error)
lgbt_spain$lower95 <- lgbt_spain$estimate - (1.96 * lgbt_spain$std.error)
lgbt_spain$higher95 <- lgbt_spain$estimate + (1.96 * lgbt_spain$std.error)
lgbt_spain$lower99 <- lgbt_spain$estimate - (2.58 * lgbt_spain$std.error)
lgbt_spain$higher99 <- lgbt_spain$estimate + (2.58 * lgbt_spain$std.error)
lgbt_spain$lower999 <- lgbt_spain$estimate - (3.29 * lgbt_spain$std.error)
lgbt_spain$higher999 <- lgbt_spain$estimate + (3.29 * lgbt_spain$std.error)
lgbt_spain<-subset(lgbt_spain, feature %in% c("PARTY")) 

gen1<- ggplot(lgbt_spain, aes(y = level, x = estimate, color = BY)) +
  scale_shape_manual(values = c(10, 18)) +
  scale_fill_manual(values = col2) +
  scale_color_manual(values = col2) +
  facet_grid(feature~., scales='free', space='free') +  
  geom_vline(xintercept = 0, colour="grey", linetype="dashed")+
  geom_segment(data = subset(lgbt_spain, BY == "LGBTQ+"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(lgbt_spain, BY == "LGBTQ+"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(lgbt_spain, BY == "LGBTQ+"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6, position = position_nudge(y = .2)) + 
  geom_point(data = subset(lgbt_spain, BY == "LGBTQ+"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21,  
             position = position_nudge(y = .2))+
  geom_segment(data = subset(lgbt_spain, BY == "Heterosexual"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1) + 
  geom_segment(data = subset(lgbt_spain, BY == "Heterosexual"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8) + 
  geom_segment(data = subset(lgbt_spain, BY == "Heterosexual"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6) + 
  geom_point(data = subset(lgbt_spain, BY == "Heterosexual"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21) +
  geom_label(data = subset(lgbt_spain, BY == "LGBTQ+"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = .4), size = 3, fontface = "bold"
  ) +
  geom_label(data = subset(lgbt_spain, BY == "Heterosexual"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = -.2), size = 3, fontface = "bold"
  ) +
  annotate("label", x = -.15, y = 1.2, label = "Heterosexual",
           color="black", size=3, fontface="bold", hjust=.5)+
  annotate("label", x = -.15, y = 1, label = "LGBTQ+",
           color="grey50", size=3, fontface="bold", hjust=.5)+
  labs(y = NULL, subtitle = 'Conditional AMCE', x="")+
  theme_ggdist() +
  xlim(-.2,.5)+
  theme(legend.position = "none",
        strip.background = element_blank(),
        strip.text = element_blank(),
        plot.subtitle = element_text(face="bold", hjust=.5)) 


lgbtMM_spain <- cj(tinder_conjoint_ES, selected ~ FLAG + BI + VEG + TRANS + CONGRUENCE + ETHNICITY + EMOTION + RELATIONSHIP + DISTANCE + EDUCATION_SLIM + JOB_SLIM + PARTY,
                   id = ~ ResponseId, estimate="mm",by = ~ queer)


lgbtMM_spain$lower90 <- lgbtMM_spain$estimate - (1.645 * lgbtMM_spain$std.error)
lgbtMM_spain$higher90 <- lgbtMM_spain$estimate + (1.645 * lgbtMM_spain$std.error)
lgbtMM_spain$lower95 <- lgbtMM_spain$estimate - (1.96 * lgbtMM_spain$std.error)
lgbtMM_spain$higher95 <- lgbtMM_spain$estimate + (1.96 * lgbtMM_spain$std.error)
lgbtMM_spain$lower99 <- lgbtMM_spain$estimate - (2.58 * lgbtMM_spain$std.error)
lgbtMM_spain$higher99 <- lgbtMM_spain$estimate + (2.58 * lgbtMM_spain$std.error)
lgbtMM_spain$lower999 <- lgbtMM_spain$estimate - (3.29 * lgbtMM_spain$std.error)
lgbtMM_spain$higher999 <- lgbtMM_spain$estimate + (3.29 * lgbtMM_spain$std.error)
lgbtMM_spain<-subset(lgbtMM_spain, feature %in% c("PARTY")) 

gen2<- ggplot(lgbtMM_spain, aes(y = level, x = estimate, color = BY)) +
  scale_shape_manual(values = c(10, 18)) +
  scale_fill_manual(values = col2) +
  scale_color_manual(values = col2) +
  facet_grid(feature~., scales='free', space='free') +  
  geom_segment(data = subset(lgbtMM_spain, BY == "LGBTQ+"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(lgbtMM_spain, BY == "LGBTQ+"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8,  position = position_nudge(y = .2)) + 
  geom_segment(data = subset(lgbtMM_spain, BY == "LGBTQ+"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6, position = position_nudge(y = .2)) + 
  geom_point(data = subset(lgbtMM_spain, BY == "LGBTQ+"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21,  
             position = position_nudge(y = .2))+
  geom_segment(data = subset(lgbtMM_spain, BY == "Heterosexual"),
               aes(x = lower90, xend = higher90, y = level, yend = level),
               size = 4, alpha = 1) + 
  geom_segment(data = subset(lgbtMM_spain, BY == "Heterosexual"),
               aes(x = lower95, xend = higher95, y = level, yend = level),
               size = 3, alpha = .8) + 
  geom_segment(data = subset(lgbtMM_spain, BY == "Heterosexual"),
               aes(x = lower99, xend = higher99, y = level, yend = level),
               size = 2, alpha = .6) + 
  geom_point(data = subset(lgbtMM_spain, BY == "Heterosexual"),
             aes(x = estimate, y = level), fill = "white", color = "grey67", size = 2.5, pch = 21) +
  geom_label(data = subset(lgbtMM_spain, BY == "LGBTQ+"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = .4), size = 3, fontface = "bold"
  ) +
  geom_label(data = subset(lgbtMM_spain, BY == "Heterosexual"),
             aes(label = sprintf("%0.2f", round(estimate, digits = 2)), y = level, x = estimate),
             position = position_nudge(y = -.2), size = 3, fontface = "bold"
  )+
  labs(y = NULL, subtitle = 'Conditional MM', x="")+
  theme_ggdist() +
  xlim(.1, .7)+
  theme(legend.position = "none",
        strip.background = element_blank(),
        strip.text = element_blank(),
        axis.ticks.y = element_blank(),
        axis.text.y = element_blank(),
        plot.subtitle = element_text(face="bold", hjust=.5))

gen1+gen2
ggsave("figures_appendix/FigureA10.png", height=9, units="cm", dpi = 900)


###FIGURE A11###

EDEM <- read.dta13("data/E-DEM-Waves-Dataset.dta")
EDEM <- EDEM %>%
  mutate(Party_New = ifelse(is.na(p30a_1), p31_1, p30a_1))
head(EDEM$p30a_1)
class(EDEM$Party_New)

EDEM_Rescaled <- EDEM
rescale <- function(x) { 
  (x - min(x, na.rm = TRUE)) / (max(x, na.rm = TRUE) - min(x, na.rm = TRUE)) 
} 
vars_to_rescale <- c("p11r_2", "p11r_3", "p11r_4", "p11g_2", "p11g_3", "p11g_4") 

for (var in vars_to_rescale) { 
  EDEM_Rescaled [[var]] <- rescale(EDEM_Rescaled [[var]]) 
} 

EDEM_Rescaled$p11g_2N <- 1 - EDEM_Rescaled$p11g_2
EDEM_Rescaled$p11g_3N <- 1 - EDEM_Rescaled$p11g_3
EDEM_Rescaled$p11g_4N <- 1 - EDEM_Rescaled$p11g_4

ES_PP <- subset(EDEM_Rescaled, Party_New==1)
names(ES_PP)

meanVOX_W2 <- mean(ES_PP$p11r_2, na.rm = TRUE)
meanVOX_W3 <- mean(ES_PP$p11r_3, na.rm = TRUE)
meanVOX_W4 <- mean(ES_PP$p11r_4, na.rm = TRUE)

meanPSOE_W2 <- mean(ES_PP$p11g_2N, na.rm = TRUE)
meanPSOE_W3 <- mean(ES_PP$p11g_3N, na.rm = TRUE)
meanPSOE_W4 <- mean(ES_PP$p11g_4N, na.rm = TRUE)

ES_w2 <- ggplot(data = ES_PP) +
  geom_density(aes(x = p11r_2, fill = "VOX"), alpha = 0.5, color = "green4") +
  geom_density(aes(x = p11g_2N, fill = "PSOE"), alpha = 0.5, color = "red2") +
  ylim(0,5)+
  scale_fill_manual(values = c("red2", "green4"), labels=c("VOX", "PSOE")) +
  scale_color_manual(values = c("red2", "green4")) +
  labs(x="", subtitle = "a) Wave 2: (February 2019)") +
  theme_ggdist() +  
  theme(legend.position = "none",
        plot.subtitle = element_text(face = "bold"),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.title.y = element_blank(),
        axis.title.x = element_text(size = 10)) +
  annotate("text", x = 0, y = 3.55, label = "In-block love",
           color = "green4", size = 4, fontface = "bold", hjust = 0) +
  annotate("text", x = 0, y = 3.95, label = "Out-block hate",
           color = "red3", size = 4, fontface = "bold", hjust = 0) +
  
  geom_vline(xintercept = meanVOX_W2, linetype = "dashed", color = "green4") +
  geom_vline(xintercept = meanPSOE_W2, linetype = "dashed", color = "red2")+
  geom_label(aes(x = meanPSOE_W2, y = 4), nudge_x= .15,  label = round(meanPSOE_W2, 2), 
             color = "red2", vjust = -0.5)+
  geom_label(aes(x = meanVOX_W2, y = 4), nudge_x= -.15,  label = round(meanVOX_W2, 2), 
             color = "green4", vjust = -0.5)


ES_w3 <- ggplot(data = ES_PP) +
  geom_density(aes(x = p11r_3, fill = "VOX"), alpha = 0.5, color = "green4") +
  geom_density(aes(x = p11g_3N, fill = "PSOE"), alpha = 0.5, color = "red2") +
  ylim(0,5)+
  scale_fill_manual(values = c("red2", "green4"), labels=c("VOX", "PSOE")) +
  scale_color_manual(values = c("red2", "green4")) +
  labs(x="", subtitle = "b) Wave 3: (Abril 2019)") +
  theme_ggdist() +  
  theme(legend.position = "none",
        plot.subtitle = element_text(face = "bold"),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.title.y = element_blank(),
        axis.title.x = element_text(size = 10)) +
  
  geom_vline(xintercept = meanVOX_W3, linetype = "dashed", color = "green4") +
  geom_vline(xintercept = meanPSOE_W3, linetype = "dashed", color = "red2")+
  geom_label(aes(x = meanPSOE_W3, y = 4), nudge_x= .15,  label = round(meanPSOE_W3, 2), 
             color = "red2", vjust = -0.5)+
  geom_label(aes(x = meanVOX_W3, y = 4), nudge_x= -.15,  label = round(meanVOX_W3, 2), 
             color = "green4", vjust = -0.5)


ES_w4 <- ggplot(data = ES_PP) +
  geom_density(aes(x = p11r_4, fill = "VOX"), alpha = 0.5, color = "green4") +
  geom_density(aes(x = p11g_4N, fill = "PSOE"), alpha = 0.5, color = "red2") +
  ylim(0,5)+
  scale_fill_manual(values = c("red2", "green4"), labels=c("VOX", "PSOE")) +
  scale_color_manual(values = c("red2", "green4")) +
  labs(x="", subtitle = "c) Wave 4: (May 2019)") +
  theme_ggdist() +  
  theme(legend.position = "none",
        plot.subtitle = element_text(face = "bold"),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.title.y = element_blank(),
        axis.title.x = element_text(size = 10)) +
  
  geom_vline(xintercept = meanVOX_W4, linetype = "dashed", color = "green4") +
  geom_vline(xintercept = meanPSOE_W4, linetype = "dashed", color = "red2")+
  geom_label(aes(x = meanPSOE_W4, y = 4), nudge_x= .15,  label = round(meanPSOE_W4, 2), 
             color = "red2", vjust = -0.5)+
  geom_label(aes(x = meanVOX_W4, y = 4), nudge_x= -.15,  label = round(meanVOX_W4, 2), 
             color = "green4", vjust = -0.5)



ES_PP$Dif_W2 <- ifelse(!is.na(ES_PP$p11r_2) & !is.na(ES_PP$p11g_2N), ES_PP$p11g_2N - ES_PP$p11r_2, NA)
ES_PP$Dif_W3 <- ifelse(!is.na(ES_PP$p11r_3) & !is.na(ES_PP$p11g_3N), ES_PP$p11g_3N - ES_PP$p11r_3, NA)
ES_PP$Dif_W4 <- ifelse(!is.na(ES_PP$p11r_4) & !is.na(ES_PP$p11g_4N), ES_PP$p11g_4N - ES_PP$p11r_4, NA)

Mean_Dif_W2 <- mean(ES_PP$Dif_W2, na.rm = TRUE)
Mean_Dif_W3 <- mean(ES_PP$Dif_W3, na.rm = TRUE)
Mean_Dif_W4 <- mean(ES_PP$Dif_W4, na.rm = TRUE)

ES_dif_w2 <- ggplot(data = ES_PP) +
  geom_density(aes(x = Dif_W2, fill = "Difference"), alpha = 0.5, color = "cyan4") +
  ylim(0,5)+
  scale_fill_manual(values = c("cyan4"), labels=c("Differece")) +
  scale_color_manual(values = c("cyan4")) +
  labs(x="More in-block love – More out-block hate", subtitle = "") +
  theme_ggdist() +  
  theme(legend.position = "none",
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.title.y = element_blank(),
        axis.title.x = element_text(size = 10)) +
  annotate("text", x = 0.1, y = 4, label = "Difference",
           color = "cyan4", size = 4, fontface = "bold", hjust = 0) +
  geom_vline(xintercept = Mean_Dif_W2, linetype = "dashed", color = "cyan4")+
  geom_label(aes(x = Mean_Dif_W2, y = 4), nudge_x= .15,  label = round(Mean_Dif_W2, 2), 
             color = "cyan4", vjust = -0.5)

ES_dif_w3 <- ggplot(data = ES_PP) +
  geom_density(aes(x = Dif_W3, fill = "Difference"), alpha = 0.5, color = "cyan4") +
  ylim(0,5)+
  scale_fill_manual(values = c("cyan4"), labels=c("Differece")) +
  scale_color_manual(values = c("cyan4")) +
  labs(x="More in-block love – More out-block hate", subtitle = "") +
  theme_ggdist() +  
  theme(legend.position = "none",
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.title.y = element_blank(),
        axis.title.x = element_text(size = 10)) +
  
  geom_vline(xintercept = Mean_Dif_W3, linetype = "dashed", color = "cyan4") +
  geom_label(aes(x = Mean_Dif_W3, y = 4), nudge_x= .15, label = round(Mean_Dif_W3, 2), 
             color = "cyan4", vjust = -0.5)

ES_dif_w4 <- ggplot(data = ES_PP) +
  geom_density(aes(x = Dif_W4, fill = "Difference"), alpha = 0.5, color = "cyan4") +
  ylim(0,5)+
  scale_fill_manual(values = c("cyan4"), labels=c("Differece")) +
  scale_color_manual(values = c("cyan4")) +
  labs(x="More in-block love – More out-block hate", subtitle = "") +
  theme_ggdist() +  
  theme(legend.position = "none",
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.title.y = element_blank(),
        axis.title.x = element_text(size = 10)) +
  geom_vline(xintercept = Mean_Dif_W4, linetype = "dashed", color = "cyan4") +
  geom_label(aes(x = Mean_Dif_W4, y = 4), nudge_x= .15, label = round(Mean_Dif_W4, 2), 
             color = "cyan4", vjust = -0.5)


EScombined_plot <- (ES_w2|ES_w3|ES_w4) / (ES_dif_w2 |ES_dif_w3| ES_dif_w4) +
  plot_annotation(title = "Spain centre-right voters' in-block love & out-block hate",
                  subtitle = "Upper panel: Absolute affect for in-block & out-block partians\nLower panel: Difference negative out-block affect & positive in-bloc affect",
                  caption = "Source: E-Dem 2017-2020 Dataset") & 
  theme(plot.title = element_text(face="bold"))
ggsave("figures_appendix/FigureA11.png", dpi = 900,
       height=12, width=14)

###TABLE A7 and TABLE A8###
Spaindata <- Spaindata %>%
  mutate(partyfull = case_when(
    partyfull == 0 ~ "PSOE",
    partyfull == 1 ~ "PP",
    partyfull== 2 ~ "VOX",
    partyfull == 3 ~ "Sumar",
    partyfull == 4 ~ "Unidas Podemos",
    partyfull == 5 ~ "Other",
    partyfull == 6 ~ "Other",
    partyfull == 7 ~ "Other",
    partyfull == 8 ~ "Other",
    partyfull == 9 ~ "Other",
    TRUE ~ as.factor(partyfull)))

Spaindata <- Spaindata %>%
  mutate(
    educ = ifelse(educ == 9999, NA, educ),
    degree = case_when(
      educ < 4 ~ "No degree",
      educ >= 4 ~ "Degree",
      TRUE ~ NA_character_
    ),
    degree = as.factor(degree)
  )


Spaindata <- Spaindata %>%
  mutate(sex = case_when(
    sex == 0 ~ "Man",
    sex == 1 ~ "Woman",
    sex == 2 ~ "other",
    sex == 3 ~ "other",
    sex == 9999 ~ "other",
    TRUE ~ as.factor(sex)))

Spaindata <- Spaindata %>%
  mutate(sex_orient = case_when(
    sex_orient == 0 ~ "Heterosexual",
    sex_orient == 1 ~ "LGBTQ+",
    sex_orient == 2 ~ "LGBTQ+",
    sex_orient == 3 ~ "LGBTQ+",
    sex_orient == 4 ~ "LGBTQ+",
    sex_orient == 5 ~ "LGBTQ+",
    sex_orient == 9999 ~ "LGBTQ+",
    TRUE ~ as.factor(sex_orient)))

summ_spain <- Spaindata %>%
  select(sex, age, degree, sex_orient, rile_self, partyfull)
datasummary_skim(summ_spain, type="categorical",  output='tables_appendix/TableA7.tex')
datasummary_skim(summ_spain, output='tables_appendix/TableA8.tex')

